// import { from } from 'core-js/core/array'
import Vue from 'vue'
import VueRouter from 'vue-router'
import RecommendView from '../views/RecommendView.vue'
import ClassifyView from '../views/ClassifyView.vue'
import SearchView from '../views/SearchView.vue'
// import ClientView from '../views/ClientView.vue'
import PersonalCenter from '../views/PersonalCenter.vue'
import FictionContent from '../views/FictionContent.vue'
import DetailView from '../views/DetailView.vue'
import ContentDetails from '../views/ContentDetails.vue'
import LoginView from '../views/LoginView.vue'
import EnrollView from '../views/EnrollView.vue'
import TransLation from '../views/TransLation.vue'
import ReadRecord from '../views/ReadRecord.vue'
import RegisterView from '../views/RegisterView.vue'
import LoginVieww from '../views/LoginVieww.vue'
// import { component } from 'vue/types/umd'




Vue.use(VueRouter)

var beforeEnterfun = (to, from, next) => {
  let phone = window.localStorage.getItem("number");
  //判断是否登录
  if (!phone) {
    next("/LoginView")
    return;
  } else {
    next();
  }
}

const routes = [

  {
    path: '/',
    redirect: "/RecommendView"
  },
  {
    path: '/RecommendView',
    name: 'RecommendView',
    component: RecommendView,
  },
  {
    path: '/ClassifyView',
    name: 'ClassifyView',
    component: ClassifyView
  },
  {
    path: '/SearchView',
    name: 'SearchView',
    component: SearchView
  },
  {
    path: '/FictionContent',
    name: 'FictionContent',
    component: FictionContent,
    meta: {
      ShowAndHide: true
    },
  },
  {
    path: '/EnrollView',
    name: 'EnrollView',
    component: EnrollView
  },
  {
    path: '/LoginVieww',
    name: 'LoginVieww',
    component: LoginVieww
  },
  // {
  //   path:'/ClientView',
  //   name:'ClientView',
  //   component:ClientView
  // },


  {
    path: '/PersonalCenter',
    name: 'PersonalCenter',
    meta: {
      ShowAndHide: true
    },
    component: PersonalCenter,
    //独享路由守卫
    beforeEnter: beforeEnterfun,
  },

  // {
  //   path: '/ClientView',
  //   name: 'ClientView',
  //   component: () => import('../views/ClientView.vue')
  // },

  {
    path: '/DetailView',
    name: 'DetailView',
    component: DetailView,
    meta: {
      ShowAndHide: true
    },
  },
  {
    path: '/ContentDetails',
    name: 'ContentDetails',
    component: ContentDetails,
    meta: {
      ShowAndHide: true
    },
  },

  {
    path: '/LoginView',
    name: 'LoginView',
    component: LoginView,
    meta: {
      ShowAndHide: true
    },
  },
  {
    path: '/TransLation',
    name: 'TransLation',
    component: TransLation,


    //独享路由守卫
    beforeEnter: beforeEnterfun


    //独享路由守卫
    // beforeEnter:(to,from,next)=>{
    //   let phone = window.localStorage.getItem("number");
    //   //判断是否登录
    //   if(!phone){
    //     next("/LoginView")
    //     return;
    //   }else{
    //     next("/TransLation");
    //   }
    // }

  },

  {
    path: "/ReadRecord",
    name: "ReadRecord",
    component: ReadRecord
  },
  {
    path: "/RegisterView",
    name: "RegisterView",
    component: RegisterView
  }

  // {
  //   path: '/',
  //   name: 'home',
  //   component: HomeView
  // },
  // {
  //   path: '/about',
  //   name: 'about',
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // }
]


// 注意:解决路由跳转问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
}


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


// 配置全局路由守卫
// 用户必须登录才进入
// router.beforeEach((to,from,next)=>{
//   let phone = window.localStorage.getItem("number")
//   // 登录界面判断
//   if(to.path=="/LoginView"){
//     next();
//     return;
//   }else{
//     if(!phone){
//       next("/LoginView");
//       return;
//     }else{
//       next()
//     }
//   }
// })

export default router
